#include"Tool/tool_camera.h"
#include "Tool/tool_qrdecoder.h"
#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <QQmlContext>
#include <QThread>


int main(int argc, char *argv[])
{
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
    QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
#endif

    QGuiApplication app(argc, argv);

    //将Tool_camera类注册为qml类型
    qmlRegisterType<Tool_camera>("com.xdqd.classes", 1, 0, "Tool_camera");
    qmlRegisterType<Tool_qr>("com.xdqd.classes", 1, 0, "Tool_qr");
    QQmlApplicationEngine engine;
    //注册图像提供者
    engine.addImageProvider(QLatin1String("imageProvider"), new VideoframeProvider);

//    //实例化
//    Tool_qrdecoder  *qrdecoder=new Tool_qrdecoder;
//    QThread qrdecoderThread;
//    qrdecoder->moveToThread(&qrdecoderThread);
//    qrdecoderThread.start();
//    qrdecoder->startDecoder(200);
//    QQmlContext *context=engine.rootContext();
//    context->setContextProperty("qrdecoder",qrdecoder);

    const QUrl url(QStringLiteral("qrc:/main.qml"));
    QObject::connect(&engine, &QQmlApplicationEngine::objectCreated,
                     &app, [url](QObject *obj, const QUrl &objUrl) {
        if (!obj && url == objUrl)
            QCoreApplication::exit(-1);
    }, Qt::QueuedConnection);
    engine.load(url);

    return app.exec();
}
